<?php
declare(strict_types=1);

namespace App\Utils\Other\Payment\Sandpay;

use function Hyperf\Config\config;

/**
 * 微信小程序端
 * @package App\Utils\Other\Payment\Sandpay
 */
Class Mini extends App {

    /**
     * 支付
     * @param array $params
     * @return array
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function pay(array $params): array
    {
        $this->setPath('v4/sd-receipts/api/trans/trans.order.create');

        $params['payerInfo']['subAppId'] = $this->getConfig('jump', false)?
            $this->getConfig('app_id'):
            config('cloud.mini.app_id');

        return $this->request($params);
    }

    /**
     * 退款
     * @param array $params
     * @return array
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function refund(array $params): array
    {
        $this->setPath('v4/sd-receipts/api/trans/trans.order.refund');
        return $this->request($params);
    }

    /**
     * 订单查询
     * @param array $params
     * @return array
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function query(array $params): array
    {
        $this->setPath('v4/sd-receipts/api/trans/trans.order.query');
        return $this->request($params);
    }
}